﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace OK.SCOM.Authoring.Tools.MPElementsExtract
{
	internal enum ParseAction { ExtractNoPlaceMarks, ExtractReplaceWithPlaceMarks, Embed } 

	internal class MPProcessor
	{
		private Dictionary<string,MPElementTypeBase> m_ElementTypes;

		internal string BaseDirectory { get; set; }

		internal MPProcessor()
		{
			m_ElementTypes = new Dictionary<string,MPElementTypeBase>();
		}

		internal void AddElementType(MPElementTypeBase elementType)
		{
			if (!m_ElementTypes.ContainsKey(elementType.Name))
			{
				m_ElementTypes.Add(elementType.Name, elementType);
			}
		}

		internal void Parse(XmlDocument doc, ParseAction action)
		{
			foreach (MPElementTypeBase elementType in m_ElementTypes.Values)
			{
				if (!(action == ParseAction.Embed && !elementType.SupportsEmbed) &&
						!(action == ParseAction.ExtractReplaceWithPlaceMarks && !elementType.SupportsExtractReplaceWithPlaceMarks))
				{
					Console.WriteLine("Processing using [{0}] ...", elementType.Name);
					foreach (XmlNode node in doc.ChildNodes)
					{
						elementType.Parse(node, action);
					}
				}
			}
		}

	}
}
